<template>
<!--包时套餐-->
<view class="community">
	<view class="head_bg">
		<view class="community_msg padding-left-xs ">
			<view class="community_msg_line">
				<image class="community_msg_icon" src="../../../common/img/gongsi_bai.png" mode=""></image>
				<text class="community_msg_text text-white text-lg">{{info.residential_quarters_name}}</text>
			</view>
			<view class="community_msg_line">
				<image class="ele_address_img" src="../../../common/img/dizhi_bai.png" mode=""></image>
				<text class="community_msg_text text-white text-lg">{{info.residential_quarters_address}}</text>
			</view>
		</view>
	</view>
	<view class="" style="margin-top:-100rpx;">
		<view>
			<view class="package" v-for="(item,index) in list" :key="index">
				<view class="flex">
					<view class="flex-sub">
						<view class="time_name text-white">{{item.package_name}}</view>
						<view class="text-white time_mon">¥<text>{{item.package_price}}</text></view>
					</view>
					<view class="flex-sub margin-top-lg" @click="toBuy(item)">
						<view class="text-white text-center">
							<text class="time_time">立刻购买</text>
						</view>
					</view>
				</view>
				<view class="operating_box_inner">
					<view class="money_details_inner money_details_inner1">
						<view class="money_details_number time_add_color">{{item.charging_num}}</view>
						<view class="money_details_text time_add_color">总充电(次)</view>
					</view>
					<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
					<view class="money_details_inner money_details_inner1">
						<view class="money_details_number time_add_color">{{item.charging_time}}</view>
						<view class="money_details_text time_add_color">每次充电（小时）</view>
					</view>
					<view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view>
					<view class="money_details_inner money_details_inner1">
						<view class="money_details_number time_add_color">{{item.user_num}}</view>
						<view class="money_details_text time_add_color">剩余（次）</view>
					</view>
				</view>
			</view>
			<view style="height:100rpx;"></view>
			<view v-if="list.length==0" class="margin-top-lg text-center">
				<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
			</view>
			<!-- <view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
				{{loadingTxt}} 共({{list.length}}条记录)
			</view> -->
		</view>
	</view>
</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				info:'',
				tabIndex: 1,
				istrue: true,
				list:[],
				loadingTxt:'加载更多',
			}
		},
		onLoad(options) {
			this.info=JSON.parse(options.info)
		},
		onShow() {
			page=1;
			this.gatlist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				this.loadingTxt="加载更多"
				this.tabIndex = e.currentTarget.dataset.id;
				this.gatlist();
			},
			toTimeInfo(){
				uni.navigateTo({
					url:"/pages/user/package/package_timeinfo"
				})
			},
			gatlist(){
				let that=this;
				that.http.tokenreq({
					url: 'User/v1/villagesetmeal',
					data: {
						"residential_quarters_guid": that.info.residential_quarters_guid,
					}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						that.list=list;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			toBuy(item){
				let that=this;
				uni.showModal({
					title: '提示',
					content: '确定要购买该套餐吗?',
					success: function (res) {
						if (res.confirm) {
							that.sureBuy(item);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		    sureBuy(item){
				let that=this;
				that.http.tokenreq({
					url: 'User/v1/buysetmeal',
					data: {
						"set_meal_guid": item.set_meal_guid
					}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							title: '提示',
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url:"/pages/user/package/package_time"
									})
								}
							}
						});
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'User/v1/villagesetmeal',
					data: {
						"residential_quarters_guid": that.info.residential_quarters_guid,
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
		}
	}
</script>
<style>
	.ele_title_inner{
		color: #FFFFFF;
		font-size:36rpx;
	}
	.package{
		background-image: url(../../../common/img/go_kp.png);
		background-size: 100% 100%;
		width: 100%;
		height: 350rpx;
	}
	.time_name{
		padding: 40rpx 0 0rpx 40rpx;
		font-size:30rpx;
	}
	.time_mon{
		padding: 0 0 0 40rpx;
		font-size: 44rpx;
	}
	.time_time{
		/* padding: 70rpx 30rpx 0 0rpx; */
		background-color: #534023;
		padding: 15rpx 30rpx;
		border-radius: 40rpx;
		margin-left: 100rpx;
		margin-top: 90rpx;
	}
	.time_add{
		padding: 0rpx 30rpx 0 0;
	}
	.time_add_color{
		color:#8C6B22
	}
	.time_black{
		color: #666666 !important;
	}
	.community_msg {
	    width: 100%;
	    margin: 0 20rpx;
	}
	.head_bg{
		height: 300rpx;
	}
	.money_details_inner1{
		margin-top: 30rpx;
	}
</style>